<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://agi.corp.org/authz" prefix="authz"%>
<%@ page import="th.co.mfec.mca.common.PrivConst"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="agi" %>

<%@page import="th.co.mfec.mca.common.ProjectConstant"%><center>
    <div id="content">
      <div class="topic">Audit Log</div>
      <s:form id="mainForm" action="auditLog-search.htm" method="POST">
   	  <s:hidden id="currentPage" name="pagingBean.currentPage" value="%{pagingBean.currentPage}" />
      <s:hidden id="sortMode" name="sortMode" />
  	  <s:hidden id="uspId" name="auditLogSearchBean.uspId" />
      <s:hidden id="status" name="auditLogSearchBean.status" />
      
      <div id="searchForm" class="dataField">
        <div class="subTopic">Criteria</div>
        <div id="dialoginfo"></div>
          <div class="tableContent">
            <table>
              <tr>
                <th><s:text name="label.from" /><span class="star">*</span> :</th>
                <td><s:textfield id="fromDate" name="auditLogSearchBean.fromDate" cssClass="date" onchange="changeBEtoADYear(this)" />
                	<font class="captionText">DD/MM/YYYY</font>
                	<br><span id="errorsDiv_auditLogSearchBean.fromDate"></span>
                </td>
                <th><s:text name="label.to" /><span class="star">*</span> :</th>
                <td><s:textfield id="toDate" name="auditLogSearchBean.toDate" cssClass="date" onchange="changeBEtoADYear(this)" />
                    <font class="captionText">DD/MM/YYYY</font>
                    <br><span id="errorsDiv_auditLogSearchBean.toDate"></span>
                </td>
              </tr>
              <tr>
                <th><s:text name="label.username" /> :</th>
                <td>
                	<select name="userNameOption" id="userNameOption">
                		<option value="">-- Please Select --</option>
                	</select>
                </td>
                <th><s:text name="label.status" /> :</th>
                <td>
                	<select name="statusOption" id="statusOption">
                		<option value="">-- Please Select --</option>
                	</select>
                </td>
              </tr>
            </table>
          </div>
      </div>
      <!-- button -->
      <div class="button">
          <center>
   		  <table class="button">
            <tr>
              <td><authz:authorize granted="<%=PrivConst.S040101%>" ><span id="button"><a href="javascript:onClickSearch();"><span><s:text name="button.search" /></span></a></span></authz:authorize></td>
              <td><span id="button"><a href="javascript:onClickCancel();" ><span><s:text name="button.cancel" /></span></a></span></td>
            </tr>
            <tr>
              <th>&nbsp;</th>
              <td>&nbsp;</td>
            </tr>
    	  </table>
  		  </center>
      </div>
      
      <s:if test="%{resultList != null}">
        
        	<s:if test="%{resultList.size == 0}">
        	<div id="searchResult">
      			<div class="hr"></div>
      			<div class="subTopic">Results</div>
      			<div class="tableSearchResult">
        			<div class="alert"><%=ProjectConstant.MESSAGE_NO_RECORD_FOUND%></div>
       			</div>
    		</div>
        	</s:if>
        	<s:else>
          <div id="searchResult">
          <div class="hr"></div>
          <div class="subTopic">Results</div>
          <div class="tableSearchResult">
            <div class="pagefound">
              <table>
                <tr>
                  <td class="L">
                  	<agi:pagenavi paging="${pagingBean}" />
                    </td>
                  <td class="R">
                    <agi:pagenum paging="${pagingBean}" callback="changePage"  />
                  </td>
                </tr>
              </table>
            </div>
            <table>
              <tr>
                <th nowrap="nowrap" class="checkbox">&nbsp;</th>
                <th>Running Number</th>
                <th><a href="javascript:changeSortMode()">Date/Time</a></th>
                <th>Match Set Id</th>
                <th>Username</th>
                <th>Status</th>
              </tr>
              
              <s:iterator value="resultList" status="rowstatus" id="resultList" >
              	<tr>
                	<td class="icon"><s:set name="selectedId" value="qsMatchSetID"/>
                		<a href="javascript:onClickView('<s:property value="#selectedId"/>');"><img src="${requestScope.imageBase}/icons/view.gif" alt="View" /></a>
                	</td>
                	<td><s:property value="adlId"/></td>
                	<td><s:date name="adlDateTime" format="dd/MM/yyyy HH:mm:ss"  /></td>
                	<td><s:property value="qsMatchSetID"/></td>
                	<td><s:property value="uspUserName"/></td>
                	<td><s:property value="statusOrAction"/></td>
              	</tr>
              </s:iterator>
            </table>
            
            <div class="pagefound">
			  <table>
                <tr>
                  <td class="L">
                  	<agi:pagefound paging="${pagingBean}" />
                  	&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
                  	<agi:pagedisplay id="rowsPerPage" name="pagingBean.rowsPerPage" paging="${pagingBean}" />
                  	</td>
                  <td class="R">
                    <agi:pagenum paging="${pagingBean}" callback="changePage" />
                  </td>
                </tr>
              </table>
            </div>
            
            <br />
          </div>
          </div>
        </s:else>
        	
        </s:if>
      
      </s:form>
    </div>
</center>
<script type="text/javascript">

$j(document).ready(function() {
	AjaxUtil.setAllUserName("userNameOption", "uspId");
	$j("#alert").click(function(e){
		$j("#alert").fadeOut(500);
	});

	AjaxUtil.setAllMcaStatus("statusOption", "status");
	$j("#alert").click(function(e){
		$j("#alert").fadeOut(500);
	});
	
});

function onClickSearch(){

	var form = document.forms['auditLog-search.htm'];
    var rules=new Array();
    rules[0] = 'auditLogSearchBean.fromDate:From Date|date_le|$toDate:To Date';
    rules[1] = 'auditLogSearchBean.fromDate:From Date|required';
    rules[2] = 'auditLogSearchBean.toDate:To Date|required';
    rules[3] = 'auditLogSearchBean.fromDate:From Date|date';
    rules[4] = 'auditLogSearchBean.toDate:To Date|date';
    
    if (yav.performCheck('mainForm', rules, 'inline')){
    	$j("#mainForm").attr("action","auditLog-search.htm"); 
      	$j("#mainForm").submit();
  		
	}else{
	}
}

function onClickCancel(){
	$j("#mainForm").attr("action","auditLog-end.htm"); 
  	$j("#mainForm").submit();
	
}

function onClickView(qsMatchSetID){
	popupAuditLog(qsMatchSetID);
	
}

function changePage(page) {
	$j("#currentPage").val(page);
	$j("#mainForm")
		.attr("action","auditLog-search.htm")
		.submit(); 
}

function changeSortMode(){
	var sortMode = $j("#sortMode").val();

	if(sortMode == "ASC"){
		 $j("#sortMode").val("DESC");
	}else if(sortMode == "DESC"){
		$j("#sortMode").val("ASC");
	}

	$j("#mainForm")
	.attr("action","auditLog-search.htm")
	.submit();
	
}

</script>
